﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using CSGame.DispatcherService;
using Common;

namespace CSGame
{
	public partial class frmAuthorization : Form
	{
		DispatcherClient _dispatcher;

		public frmAuthorization()
		{
			InitializeComponent();
		}

		public frmAuthorization(DispatcherClient dispatcher)
		{
			InitializeComponent();
			this._dispatcher = dispatcher;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			if (this._dispatcher.State == System.ServiceModel.CommunicationState.Opened)
			{
				this._dispatcher.Close();
			}
			
			Application.Exit();
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			ReturnInformation retInf = _dispatcher.Autorization(txtName.Text.Trim(), txtPas.Text.Trim());
			if (retInf.Success)
			{
				this.Hide();
				Program.MainForm.Dispatcher = this._dispatcher;
				Program.MainForm.UserName = this.txtName.Text;
				Program.MainForm.Show();
			}
			else
			{
				MessageBox.Show(retInf.ErrorMsg, Resources.ErrorMsgCaption);
			}
		}
	}
}
